<template>
    <div :style="{height:'100%'}" class="my-app">
        <keep-alive>
            <router-view v-if="$route.meta.keepAlive"></router-view>
        </keep-alive>
        <router-view v-if="!$route.meta.keepAlive"></router-view>
    </div>
</template>

<script>
    export default {
        data() {
            return {};
        },
        updated: function () {
            // var task = this;
            // var named = task.$route.query.mui
            // alert(named)
            // var first = null;
            // mui.back = function () {
            //     mui.plusReady(function () {
            //         //首次按键，提示‘再按一次退出应用’
            //         if (!first) {
            //             first = new Date().getTime();
            //             if (named) {
            //                 mui.toast('退出应用');
            //                 //返回当前桌面  触发物理键返回
            //                 plus.runtime.quit();
            //             } else {
            //                 task.$router.go(-1)
            //             }
            //         }else {
            //             mui.toast('在按一次退出应用！')
            //         }
            //     })
            // };
            var task  = this;
            var named = task.$route.query.mui

            var routeName = task.$route.name;
            var first = null;
            mui.back  = function () {
                if (!first) {
                    if (named || routeName == 'home' || routeName == 'login') {
                        first = new Date().getTime();
                        mui.toast('再按一次退出应用');
                        setTimeout(function () {
                            first = null;
                        }, 1000);
                    } else {
                        task.$router.go(-1)
                    }
                } else {
                    if (new Date().getTime() - first < 1000) {
                        plus.runtime.quit();
                    }
                }
            }
        },
        created() {
            if (localStorage.getItem('token')) {
                this.$router.push({
                    path: `/home`
                })

            } else {
                this.$router.push({
                    path: `/login`
                })
            }
        }
    };
</script>

<style>
    * {
        -webkit-user-select: none;
    }

    .clearfix {
        clear: both;
    }

    *, ::after, ::before {
        box-sizing: border-box;
    }

    html::-webkit-scrollbar {
        display: none
    }

    .loading-no-more {
        width: 100%;
        text-align: center;
        font-size: 13px;
        color: #999;
        line-height: 50px;
    }

    .my-app van-button:active::before {
        opacity: .04;
    }
</style>
